<template>
 <el-select
        v-model="selectedValue"
        filterable
        placeholder="请输入关键字"
      >
        <el-option
          v-for="item in selectData"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
</template>

<script setup>
import { defineOptions , defineProps ,defineEmits , onBeforeMount ,ref} from "vue";
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";
import * as ip from '../../api/ip/ip.js'
defineOptions({ name: "HhSelect" });

const emits = defineEmits(['address']);
const props = defineProps({
  type:'tenant',
  parentId: 0,
  menuType: 0,
  value: ''
})

const selectData = ref([])

const loading = ref(false)

const searFrom = ref({
    pageNo: 1,
    pageSize: 999999999,
})

const selectedValue = ref(null)

const init = () => {
    searFrom.value.parentId = props.parentId
    searFrom.value.menuType = props.menuType
    switch(props.type){
        case'tenant': tenantList(); break;
        case'menu': menuList(); break;
        case'category': categoryList(); break;
    }
}

const tenantList = async () => {
    const res = await tenantApi.page(searFrom.value);
    const { records } = res;
    records.forEach(element => {
        const item = {}
        item.label = element.name,
        item.value = element
        selectData.value.push(item);
    });
}

const typeChange = (e) => {
    emits('change',e)
}

onBeforeMount(()=>{
    init()
})

const remoteMethod = (query) => {
  if (query) {
    loading.value = true
    setTimeout(() => {
      loading.value = false
      selectData.value = selectData.value.filter((item) => {
        return item.label.includes(query)
      })
    }, 200)
  } else {
    selectData.value = []
  }
}



</script>

<style lang="less" scoped>
</style>